package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Project;
import com.ruoyi.system.mapper.TopicMapper;
import com.ruoyi.system.service.IDemandService;
import com.ruoyi.system.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * 需求Service业务层处理
 *
 * @author EdwardXRX
 * @date 2024-04-12
 */
@Service
public class TopicServiceImpl implements ITopicService {
    @Autowired
    private TopicMapper topicMapper;

    /**
     * 查询需求
     *
     * @param id 需求主键
     * @return 需求
     */
    @Override
    public Project selectProjectById(Long id) {
        Project project = topicMapper.selectProjectById(id);
        project.setClickNum(project.getClickNum() + 1);
        topicMapper.updateProject(project);
        return project;
    }

    /**
     * 查询需求列表
     *
     * @param project 需求
     * @return 需求
     */
    @Override
    public List<Project> selectProjectList(Project project) {
        return topicMapper.selectProjectList(project);
    }

    /**
     * 新增需求
     *
     * @param topic 需求
     * @return 结果
     */
    @Override
    public int insertProject(Project topic) {
        topic.setType(2);
        //直接设置审核员为两个管理员
        //胡昊
        topic.setChecker1(1000043642L);
        //吴兆发
        topic.setChecker2(1000068884L);
        topic.setClickNum(0);
        topic.setCreateTime(new Date());
        //设置为不可见
        topic.setIsShow(0);
        //设置新建的状态
        topic.setState(0);
        topic.setCreateTime(DateUtils.getNowDate());
        return topicMapper.insertProject(topic);
    }

    /**
     * 修改需求
     *
     * @param project 需求
     * @return 结果
     */
    @Override
    public int updateProject(Project project) {
        return topicMapper.updateProject(project);
    }

    /**
     * 批量删除需求
     *
     * @param ids 需要删除的需求主键
     * @return 结果
     */
    @Override
    public int deleteProjectByIds(Long[] ids) {
        return topicMapper.deleteProjectByIds(ids);
    }

    /**
     * 删除需求信息
     *
     * @param id 需求主键
     * @return 结果
     */
    @Override
    public int deleteProjectById(Long id) {
        return topicMapper.deleteProjectById(id);
    }

    @Override
    public List<Project> selectProjectListByUserId(Long userId) {
        return topicMapper.selectProjectListByUserId(userId);
    }

    @Override
    public List<Project> listTopicByClickNum() {

        return topicMapper.listTopicByClickNum();
    }

    @Override
    public Project getPreProject(Long id) {
        return topicMapper.getPreProject(id);
    }

    @Override
    public Project getNextProject(Long id) {
        return topicMapper.getNextProject(id);
    }

    @Override
    public List<Project> selectProjectByUserId(Long userId) {
        return topicMapper.selectProjectByUserId(userId);
    }
}
